<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Echo Network - 全部文章</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
            color: #333;
        }
        /* 导航栏样式 */
        .navbar {
            background-color: #2c3e50;
            color: white;
            padding: 15px 0;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 1000;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        .navbar-container {
            max-width: 960px;
            margin: 0 auto;
            padding: 0 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .navbar-logo {
            font-size: 1.5rem;
            font-weight: bold;
            color: white;
            text-decoration: none;
        }
        .navbar-menu {
            display: flex;
            list-style: none;
            margin: 0;
            padding: 0;
        }
        .navbar-menu li {
            margin-left: 20px;
        }
        .navbar-menu a {
            color: white;
            text-decoration: none;
            padding: 8px 12px;
            border-radius: 4px;
            transition: background-color 0.2s;
        }
        .navbar-menu a:hover {
            background-color: rgba(255, 255, 255, 0.1);
        }
        /* 容器样式调整，为固定导航栏留出空间 */
        .container {
            max-width: 960px;
            margin: 0 auto;
            padding: 100px 20px 40px;
        }
        h1 {
            font-size: 2.5rem;
            margin-bottom: 20px;
            color: #2c3e50;
            text-align: center;
        }
        h2 {
            font-size: 1.8rem;
            margin: 40px 0 20px 0;
            color: #2c3e50;
        }
        .card {
            background-color: #fff;
            border-radius: 8px;
            padding: 30px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            margin-bottom: 20px;
            transition: transform 0.2s, box-shadow 0.2s;
        }
        .card:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
        }
        .card h3 {
            margin-top: 0;
            font-size: 1.4rem;
            color: #2c3e50;
        }
        .card h3 a {
            color: #2c3e50;
            text-decoration: none;
        }
        .card h3 a:hover {
            color: #3498db;
            text-decoration: underline;
        }
        .card-meta {
            font-size: 0.9rem;
            color: #7f8c8d;
            margin-bottom: 15px;
        }
        .card-content {
            color: #333;
            line-height: 1.6;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
        }
        .footer {
            margin-top: 50px;
            font-size: 0.9rem;
            color: #95a5a6;
            text-align: center;
        }
        .welcome-section {
            text-align: center;
            margin-bottom: 40px;
        }
        .no-articles {
            text-align: center;
            padding: 40px;
            color: #7f8c8d;
        }
        .user-info {
            margin: 20px 0;
            padding: 15px;
            background-color: #f0f9ff;
            border-radius: 4px;
            text-align: center;
        }
        /* 退出登录按钮已删除 */
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar">
        <div class="navbar-container">
            <!-- Logo -->
            <a href="/echo-network/article-list" class="navbar-logo">Echo Network</a>
            
            <!-- 导航菜单 -->
            <ul class="navbar-menu">
                <!-- 首页（对所有用户可见） -->
                <li><a href="/echo-network/article-list">首页</a></li>
                
                <!-- 仅登录用户可见的菜单 -->
                <li th:if="${session.loginUser != null}"><a href="/echo-network/profile-show">个人中心</a></li>
                <li th:if="${session.loginUser != null}"><a href="/echo-network/article-show">我的文章</a></li>
                <li th:if="${session.loginUser != null}"><a href="/echo-network/article-publish">发布文章</a></li>
            </ul>
        </div>
    </nav>
    
    <div class="container">
        <div class="welcome-section">
            <h1>Echo Network</h1>
            <p>欢迎来到“回声网络”知识交流平台，分享你的想法和知识</p>
            
            <!-- 登录用户信息 (服务器端渲染) -->
            <div th:if="${session.loginUser != null}" class="user-info">
                <p>您已登录为：<span th:text="${session.loginUser.username}"></span></p>
                <!-- 退出登录按钮已删除 -->
            </div>
            
            <!-- 未登录时显示的登录链接 (服务器端渲染) -->
            <div th:unless="${session.loginUser != null}">
                <p><a href="login.html">登录</a> 或 <a href="register.html">注册</a> 开始使用</p>
            </div>
        </div>

        <!-- 分类筛选 -->
        <div style="margin: 20px 0; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);">
            <form action="/echo-network/article-list" method="get">
                <div style="display: flex; align-items: center; gap: 10px;">
                    <label for="categoryFilter">按分类筛选：</label>
                    <select id="categoryFilter" name="categoryId" style="padding: 8px; border: 1px solid #ddd; border-radius: 4px;">
                        <option value="">全部分类</option>
                        <option th:each="category : ${categories}" th:value="${category.categoryId}" th:text="${category.categoryName}" th:selected="${category.categoryId == selectedCategoryId}"></option>
                    </select>
                    <button type="submit" style="background: #3498db; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;">筛选</button>
                </div>
            </form>
        </div>
        
        <!-- 文章列表 -->
        <h2>
            <span th:if="${selectedCategoryId == null}">全部文章</span>
            <th:block th:unless="${selectedCategoryId == null}">
                <th:block th:each="category : ${categories}">
                    <span th:if="${category.categoryId == selectedCategoryId}" th:text="${category.categoryName} + '分类文章'"></span>
                </th:block>
            </th:block>
        </h2>
        
        <!-- 有文章时显示 -->
        <div th:if="${articles != null and not articles.empty}">
            <div th:each="article : ${articles}" class="card">
                <h3><a th:href="'/echo-network/article-detail?id=' + ${article.id}" th:text="${article.title}"></a></h3>
                <div class="card-meta">
                    <span th:text="${article.authorUsername}"></span> · 
                    <span th:text="${article.createTime}"></span>
                </div>
                <div class="card-content" th:text="${article.content}"></div>
            </div>
        </div>
        
        <!-- 无文章时显示 -->
        <div th:unless="${articles != null and not articles.empty}" class="no-articles">
            <p>暂无文章</p>
        </div>

        <div class="footer">
            <p>© 2023 Echo Network. All rights reserved.</p>
        </div>
    </div>
</body>
</html>